<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQuery尺寸和位置操作</title>
    <style>
        *{
            margin:0px;
            padding:0px;
        }
        .father{
            width:100px;
            height:100px;
            background-color:red;
            border:10px solid black;
            position:relative;
        }
        .son{
            width:50px;
            height:50px;
            background-color:blue;
            position:absolute;
            left:50px;
            top:50px;
            transform:translate(-50%,-50%);
        }

    </style>
    <script src="./js/jquery-1.12.4.js"></script>
    <script>
      $(
          function(){
              console.log($('.father').width());    //获取父元素的宽度并打印
              $('.father').width('500');    //设置父元素的宽度

              console.log($('.son').offset().left);    //获取子元素左边到窗口的距离

              console.log($('.son').position().left);    //取子元素左边到定位元素(包含块)的距离
          }
      )
    </script>
</head>
<body>
    <div class="father">
        <div class="son"></div>
    </div>
</body>
</html>